﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Projektarbete
{
    static class Input // Används för att hantera input (durr) mellan klasser och states
    {
        static KeyboardState keyState;
        static KeyboardState lastKeyState;

        static MouseState mouseState;
        static MouseState lastMouseState;

        public static KeyboardState KeyState { get { return keyState; } }
        public static KeyboardState LastKeyState { get { return lastKeyState; } }

        public static MouseState MouseState { get { return mouseState; } }
        public static MouseState LastMouseState { get { return lastMouseState; } }

        public static void Update()
        {
            lastKeyState = keyState;
            lastMouseState = mouseState;

            keyState = Keyboard.GetState();
            mouseState = Mouse.GetState();
        }

        public static bool IsKeyDown(Keys key)
        {
            return keyState.IsKeyDown(key);
        }

        public static bool IsKeyUp(Keys key)
        {
            return keyState.IsKeyUp(key);
        }

        public static bool IsNewPress(Keys key)
        {
            return (keyState.IsKeyDown(key) && lastKeyState.IsKeyUp(key));
        }

        public static bool IsMouseOneDown()
        {
            return mouseState.LeftButton == ButtonState.Pressed;
        }

        public static bool IsMouseTwoDown()
        {
            return mouseState.RightButton == ButtonState.Pressed;
        }

        public static bool IsNewMouseOnePress()
        {
            return (mouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released); 
        }

        public static bool IsNewMouseTwoPress()
        {
            return (mouseState.RightButton == ButtonState.Pressed && lastMouseState.RightButton == ButtonState.Released); 
        }

        public static int GetMouseWheelValueNormalized()
        {
            return mouseState.ScrollWheelValue / 120;
        }

        public static int GetLastMouseWheelValueNormalized()
        {
            return lastMouseState.ScrollWheelValue / 120;
        }

        public static Point GetMousePosition()
        {
            return new Point(mouseState.X, mouseState.Y);
        }
    }
}
